/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-04-19     sethnie       the first version
 */

#ifndef __DRV_LCD_H
#define __DRV_LCD_H
#include"debug.h"
#include"stdlib.h"
#include <rtthread.h>

//#define  delay_ms(x)  rt_thread_mdelay(x)
//#define  delay_us(x)  Delay_Us(x)

#define LCD_W 320
#define LCD_H 240

/* LCD parameter */
typedef struct
{
    rt_uint16_t width;
    rt_uint16_t height;
    rt_uint16_t id;             //LCD ID
    rt_uint8_t  dir;
    rt_uint16_t wramcmd;
    rt_uint16_t setxcmd;
    rt_uint16_t setycmd;
}_lcd_dev;


extern _lcd_dev lcddev;
extern rt_uint16_t POINT_COLOR;
extern rt_uint16_t BACK_COLOR;


/* LCD addr */
typedef struct
{
    vu16 LCD_REG;
    vu16 LCD_RAM;
} LCD_TypeDef;

/* A17, Bank1, sector1 */
#define LCD_BASE        ((rt_uint32_t)(0x60000000 | 0x0003FFFE))
#define LCD             ((LCD_TypeDef *) LCD_BASE)

/* Scan direction definition */
#define L2R_U2D  0
#define L2R_D2U  1
#define R2L_U2D  2
#define R2L_D2U  3

#define U2D_L2R  4
#define U2D_R2L  5
#define D2U_L2R  6
#define D2U_R2L  7

#define DFT_SCAN_DIR  L2R_U2D

/* Colour */
#define WHITE            0xFFFF
#define BLACK            0x0000
#define BLUE             0x001F
#define BRED             0XF81F
#define GRED             0XFFE0
#define GBLUE            0X07FF
#define RED              0xF800
#define MAGENTA          0xF81F
#define GREEN            0x07E0
#define CYAN             0x7FFF
#define YELLOW           0xFFE0
#define BROWN            0XBC40
#define BRRED            0XFC07
#define GRAY             0X8430

#define DARKBLUE         0X01CF
#define LIGHTBLUE        0X7D7C
#define GRAYBLUE         0X5458

#define LIGHTGREEN       0X841F
#define LGRAY            0XC618

#define LGRAYBLUE        0XA651
#define LBBLUE           0X2B12

void LCD_Init(void);
void LCD_Clear(rt_uint16_t Color);
void LCD_SetCursor(rt_uint16_t Xpos, rt_uint16_t Ypos);
void LCD_WriteReg(rt_uint16_t LCD_Reg, rt_uint16_t LCD_RegValue);
rt_uint16_t LCD_ReadReg(rt_uint16_t LCD_Reg);
void LCD_WriteRAM_Prepare(void);
void LCD_WriteRAM(rt_uint16_t RGB_Code);
void LCD_Scan_Dir(rt_uint8_t dir);
void LCD_Display_Dir(rt_uint8_t dir);
void LCD_Set_Window(rt_uint16_t sx,rt_uint16_t sy,rt_uint16_t width,rt_uint16_t height);
void LCD_Fast_DrawPoint(rt_uint16_t x,rt_uint16_t y,rt_uint16_t color);
void LCD_ShowChar(rt_uint16_t x,rt_uint16_t y,rt_uint8_t num,rt_uint8_t size,rt_uint8_t mode);
void LCD_ShowNum(rt_uint16_t x,rt_uint16_t y,rt_uint32_t num,rt_uint8_t len,rt_uint8_t size);
void LCD_ShowString(rt_uint16_t x,rt_uint16_t y,rt_uint16_t width,rt_uint16_t height,rt_uint8_t size,rt_uint8_t *p);

#endif


